package 选课系统;


public class Course {
	public String course_id;
	public String course_name;
	public String course_where;
	public String course_time;
	public Teacher teacher;
	public Student[] students;


	//构造函数
	public Course(String course_id,String course_name,String course_where,String course_time,Teacher teacher) {
		this.course_id = course_id;
		this.course_name = course_name;
		this.course_where = course_where;
		this.course_time = course_time;
		this.setTeacher(teacher);
		students = new Student[3];
	}
	
	
	public Course(String course_id,String course_name,String course_where,String course_time) {
		this.course_id = course_id;
		this.course_name = course_name;
		this.course_where = course_where;
		this.course_time = course_time;
		students = new Student[3];
	}
	
	
	public Course() {
		students = new Student[3];
	}
	
	
	//获取课程id或者修改id
	public void setCourse_id(String course_id) {
		this.course_id = course_id;
	}
	
	public String getCourse_id() {
		return this.course_id;
	}
	
	
	//获取课程名称
	public void setCourse_name(String course_name) {
		this.course_name = course_name;
	}
	
	public String getCourse_name() {
		return this.course_name;
	}
	
	
	//获取上课地点
	public void setCourse_where(String course_where) {
		this.course_where = course_where;
	}
	
	public String getCourse_where() {
		return this.course_where;
	}
	
	
	//获取上课时间
	public void setCourse_time(String course_time) {
		this.course_time = course_time;
	}
	
	public String getCourse_time() {
		return this.course_time;
	}
	
	
	//授课老师
	public Teacher getTeacher() {
		return teacher;
	}
	
	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}
	
	
	//学生选课
	public boolean addStudent(Student stu) {
		boolean flag = false;
		for(int i = 0;i<students.length;i++) {
			if (students[i] == null) {
				students[i] = stu;
				flag = true;
				break;
			}
		}
		return flag;
	}

	
	//学生退课
	public boolean removeStudent(Student stu) {
		boolean flag = false;
		for(int i = 0;i<students.length;i++) {
			if (students[i] == stu) {
				students[i] = null;
				flag = true;
				break;
			}
		}
		return flag;
	}
	
	
	//显示选择课程的学生：
	public void displayStudent() {
		System.out.println("选择"+this.course_name+"的学生有：");
		for(Student s:students) {
			if(s != null) {
				System.out.print(s.getName()+" \n");
			}
		}
	}
}
